

package com.hex.ds.code.detection.config.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hex.ds.code.detection.config.model.ConfigPropertyParam;
import com.hex.ds.code.detection.common.annotation.AnonymousAccess;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import com.hex.ds.code.detection.config.service.ConfigPropertyParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 参数化配置param表
 *
 * @author zl
 * @date 2024-02-04 14:42:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/configpropertyparam" )
@Api(value = "configpropertyparam", tags = "参数化配置param表管理")
public class ConfigPropertyParamController {

    private final  ConfigPropertyParamService configPropertyParamService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param configPropertyParam 参数化配置param表
     * WrapperEnhancer.like(configPropertyParam); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @AnonymousAccess
    public ResponseEntity<Object> getConfigPropertyParamPage(Page page, ConfigPropertyParam configPropertyParam) {
        return new ResponseEntity<>(configPropertyParamService.queryList(page, configPropertyParam), HttpStatus.OK);
    }


    /**
     * 通过id查询参数化配置param表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @AnonymousAccess
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(configPropertyParamService.getById(id));
    }

    /**
     * 通过集群id查询参数化配置param表
     * @param clusterId
     * @return R
     */
    @ApiOperation(value = "通过集群id查询", notes = "通过集群id查询")
    @GetMapping("/cluster/{clusterId}")
    @AnonymousAccess
    public ResponseEntity<Object> getClusterById(@PathVariable("clusterId" ) String clusterId) {
        return new ResponseEntity<>(configPropertyParamService.getListByClusterId(clusterId), HttpStatus.OK);
    }


    /**
     * 新增参数化配置param表
     * @param configPropertyParam 参数化配置param表
     * @return R
     */
    @ApiOperation(value = "新增参数化配置param表", notes = "新增参数化配置param表")
    @PostMapping
    @AnonymousAccess
    public ResponseEntity<Object> save(@RequestBody ConfigPropertyParam configPropertyParam) {
        return ResponseEntity.ok(configPropertyParamService.save(configPropertyParam));
    }

    /**
     * 修改参数化配置param表
     * @param configPropertyParam 参数化配置param表
     * @return R
     */
    @ApiOperation(value = "修改参数化配置param表", notes = "修改参数化配置param表")
    @PutMapping
    @AnonymousAccess
    public ResponseEntity<Object> updateById(@RequestBody ConfigPropertyParam configPropertyParam) {
        return ResponseEntity.ok(configPropertyParamService.updateById(configPropertyParam));
    }

    /**
     * 通过id删除参数化配置param表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除参数化配置param表", notes = "通过id删除参数化配置param表")
    @DeleteMapping("/{id}" )
    @AnonymousAccess
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(configPropertyParamService.removeById(id));
    }

}
